/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Main;

import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author
 */
public class LoaiNguoiDung {
    //Danh sach thuoc tinh
    private int maLoai;
    private String tenLoai;

    //Danh sach hamg get va set
    public int getMaLoai() {
        return maLoai;
    }

    public void setMaLoai(int maLoai) {
        this.maLoai = maLoai;
    }

    public String getTenLoai() {
        return tenLoai;
    }

    public void setTenLoai(String tenLoai) {
        this.tenLoai = tenLoai;
    }
    
    //Ham lay danh sach loai nguoi dun
    public static List<LoaiNguoiDung> layDanhSachLoaiNguoiDung(){
       List<LoaiNguoiDung> danhSach = new ArrayList<LoaiNguoiDung>();
        String sql = "select * from loai_nguoi_dung";
        try {
            //Tao bien ket noi
            Connection connection = KetNoiCSDL.open();
            // Tao bien statement de truy van
            PreparedStatement statement = (PreparedStatement) connection.prepareStatement(sql);
            //Tra ve result set sau khi truy van du lieu
            ResultSet rs = statement.executeQuery();
            //Lap lay tung dong du lieu
            while (rs.next()) {

                LoaiNguoiDung lnd = new LoaiNguoiDung();
                lnd.maLoai=rs.getInt("id");
                lnd.tenLoai=rs.getString("ten_loai");
                danhSach.add(lnd);

            }
            connection.close();
        } catch (Exception ex) {
            ex.printStackTrace();
            KetNoiCSDL.close();
        } finally {
            KetNoiCSDL.close();
        }
        return danhSach;
    }
    
}
